package kassiopeia.commons.util;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import org.apache.log4j.Logger;
import com.google.common.io.Resources;

public final class IOUtils {

    private static final Logger logger = Logger.getLogger(IOUtils.class);
    private static final Charset charset = Charset.defaultCharset();

    private IOUtils() {}

    public static String getFileContent(String resourceName) {
        try {
            URL resourceUrl = Resources.getResource(resourceName);
            return Resources.toString(resourceUrl, charset);
        } catch(IOException exception) {
            logger.error("Can't get file content " + resourceName, exception);
            return null;
        }
    }

    public static byte[] getByteContent(String resourceName) {
        try {
            URL resourceUrl = Resources.getResource(resourceName);
            return Resources.toByteArray(resourceUrl);
        } catch(IOException exception) {
            logger.error("Can't get file content " + resourceName, exception);
            return null;
        }
    }
}
